package cn.com.darly.vpm.mobile;

import cn.com.darly.vpm.business.BusinessApi;
import cn.com.darly.vpm.business.amuse.bean.Amuse;
import cn.com.darly.vpm.framework.common.StringDiyUtils;
import cn.com.darly.vpm.mobile.cfg.MobileBaseController;
import cn.com.darly.vpm.security.securitycfg.SecurityApi;
import cn.com.darly.vpm.security.user.bean.User;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户登录完成后，获取的用户关联信息类，包括获取用户好友。用户好友信息
 * @author Darly/张宇辉/2018/5/8 10:21
 * @version 1.0/cn.com.darly.vpm.mobile
 */
@Controller
@RequestMapping("mobile/index")
public class NoUserController extends MobileBaseController {
    @Autowired
    BusinessApi businessApi;
    @Autowired
    SecurityApi api;
    /**
     * @return 新用户注册接口
     */
    @RequestMapping(value = {"/amuse"}, method = RequestMethod.POST)
    public void indexAmuse(HttpServletRequest request, HttpServletResponse response){
        if (!StringDiyUtils.isEmpty(request.getParameter("pageNo"))){
            pageNo  = Integer.parseInt(request.getParameter("pageNo"));
        }
        if (!StringDiyUtils.isEmpty(request.getParameter("pageSize"))) {
            pageSize = Integer.parseInt(request.getParameter("pageSize"));
        }

        PageInfo<Amuse> pageInfo = businessApi.getAmuseByPager(pageNo,pageSize);
        if (pageNo>pageInfo.getPageNum()){
            simpleResult("201","没有更多数据",request,response);
        }else {
            List<Amuse> data = pageInfo.getList();
            for (Amuse amuse: data) {
                User user =  api.findUserById(amuse.getAuthor());
                if (user!=null){
                    amuse.setUser(user);
                }
            }
            simplePageInfo("200", "查询成功", pageInfo, request, response);
        }
    }
}
